package ACM_Brush;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Scanner;

public class Solution84 {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int num = in.nextInt();
            int[] heights = new int[num];
            for (int i = 0; i < num; i++) {
                heights[i] = in.nextInt();
            }
            System.out.println();
            System.out.println(new solution_084().largestRectangleArea(heights));
        }

    }
}

class solution_084 {
    public int largestRectangleArea(int[] heights) {
        int[] Heights = new int[heights.length + 2];
        System.arraycopy(heights, 0, Heights, 1, heights.length);
        Heights[0] = 0;
        Heights[Heights.length - 1] = 0;

        Deque<int[]> stack = new LinkedList<>();

        stack.push(new int[] { Heights[0], 0 });

        int maxArea = 0;

        for (int i = 1; i < Heights.length; i++) {
            while (!stack.isEmpty() && Heights[i] < stack.peek()[0]) {
                int col = stack.pop()[0];
                maxArea = Math.max(maxArea, col * (i - stack.peek()[1] - 1));
            }
            stack.push(new int[] { Heights[i], i });
        }

        return maxArea;
    }
}